/*
 * @lc app=leetcode.cn id=2073 lang=typescript
 *
 * [2073] 买票需要的时间
 */

// @lc code=start
function timeRequiredToBuy(tickets: number[], k: number): number {
    let count = 0;
    let mine = tickets[k];
    tickets.forEach((i, index) => {
        if (index <= k) {
            count += Math.min(i, mine);
        } else {
            count += Math.min(i, mine - 1);
        }
    });
    return count;
}
// @lc code=end
